home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 June / EnigmA AMIGA RUN 08 (1996)(G.R. Edizioni)(IT)[!][issue 1996-06][EARSAN CD VII].iso / earcd / hardware / galer21.lha / GALer21 / Source / GALer / GALasm.c < prev    next >
C/C++ Source or Header  |  1996-04-05  |  83KB  |  2,614 lines

  1. /******************************************************************************
  2. ** GALasm.c
  3. *******************************************************************************
  4. **
  5. ** description:
  6. **
  7. ** This file contains the GAL-assembler.
  8. **
  9. ******************************************************************************/
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16. /********************************* includes **********************************/
  17.  
  18. #include <exec/types.h>
  19. #include <exec/memory.h>
  20. #include <intuition/intuition.h>
  21. #include <libraries/locale.h>
  22. #include <ctype.h>
  23. #include <stdio.h>
  24. #include <string.h>
  25.  
  26. #include <proto/locale.h>
  27. #include <proto/intuition.h>
  28. #include <proto/exec.h>
  29.  
  30. #include "GALer.h"
  31. #include "Localize.h"
  32.  
  33.  
  34.  
  35.  
  36. /********************************** defines **********************************/
  37.  
  38. #define SUFFIX_NON              0       /* possible suffixes */
  39. #define SUFFIX_T                1
  40. #define SUFFIX_R                2
  41. #define SUFFIX_E                3
  42. #define SUFFIX_CLK              4
  43. #define SUFFIX_APRST            5
  44. #define SUFFIX_ARST             6
  45.  
  46. #define DUMMY_OLMC11            24
  47. #define DUMMY_OLMC12            25
  48.  
  49.  
  50.  
  51.  
  52.  
  53. /******************************** functions **********************************/
  54.  
  55.  
  56.  
  57.  
  58.  
  59. /******************************** variables **********************************/
  60.  
  61. extern  struct  AppString { LONG   as_ID;
  62.                             STRPTR as_Str;
  63.                           };
  64.  
  65. extern  struct  AppString AppStrings[];
  66.  
  67.  
  68. extern  int     linenum, MaxFuseAdr, SigAdr, RowSize, GALType;
  69. extern  UBYTE   *actptr, *buffend;
  70. extern  char    path;
  71.  
  72.  
  73. extern  struct  JedecStruct     Jedec;
  74. extern  struct  Configuration   Config;
  75. extern  struct  Catalog         *catalog;
  76.  
  77. struct  Pin             actPin;
  78. struct  GAL_OLMC        OLMC[12];
  79.  
  80.  
  81.                       /* Diese Arrays geben an, in welche Spalte der ent-  */
  82.                       /* sprechende Pin eingekoppelt (bzw. rückgekoppelt)  */
  83.                       /* wird. Für die invertierende Einkopplung ist 1 zu  */
  84.                       /* addieren, um die entsprechende Spalte zu erhalten */
  85.                       /* -1 heißt: keine Einkopplung auf Matrix vorhanden  */
  86.  
  87.                         /* GAL16V8 */
  88. int     PinToFuse16Mode1[20]    = {  2,  0,  4,  8, 12, 16, 20, 24, 28, -1,
  89.                                     30, 26, 22, 18, -1, -1, 14, 10,  6, -1 };
  90.  
  91. int     PinToFuse16Mode2[20]    = {  2,  0,  4,  8, 12, 16, 20, 24, 28, -1,
  92.                                     30, -1, 26, 22, 18, 14, 10,  6, -1, -1 };
  93.  
  94. int     PinToFuse16Mode3[20]    = { -1,  0,  4,  8, 12, 16, 20, 24, 28, -1,
  95.                                     -1, 30, 26, 22, 18, 14, 10,  6,  2, -1 };
  96.  
  97.                         /* GAL20V8 */
  98. int     PinToFuse20Mode1[24]    = {  2, 0, 4, 8,12,16,20,24,28,32,36,-1,
  99.                                     38,34,30,26,22,-1,-1,18,14,10, 6,-1 };
  100.  
  101. int     PinToFuse20Mode2[24]    = {  2, 0, 4, 8,12,16,20,24,28,32,36,-1,
  102.                                     38,34,-1,30,26,22,18,14,10,-1, 6,-1 };
  103.  
  104. int     PinToFuse20Mode3[24]    = { -1, 0, 4, 8,12,16,20,24,28,32,36,-1,
  105.                                     -1,38,34,30,26,22,18,14,10, 6, 2,-1 };
  106.  
  107.  
  108.                         /* GAL22V10 */
  109. int     PinToFuse22V10[24]      = {  0, 4, 8,12,16,20,24,28,32,36,40,-1,
  110.                                     42,38,34,30,26,22,18,14,10, 6, 2,-1 };
  111.  
  112.  
  113.                         /* GAL20RA10 */
  114. int     PinToFuse20RA10[24]     = { -1, 0, 4, 8,12,16,20,24,28,32,36,-1,
  115.                                     -1,38,34,30,26,22,18,14,10, 6, 2,-1 };
  116.  
  117.  
  118.  
  119.  
  120.                         /* these arrays show which row is connected to */
  121.                         /* which OLMC */
  122.  
  123. int     ToOLMC[8]         = { 56, 48, 40, 32, 24, 16, 8, 0 };
  124.  
  125. int     ToOLMC22V10[12]   = { 122, 111, 98, 83, 66, 49, 34, 21, 10, 1, 0, 131 };
  126.  
  127. int     ToOLMC20RA10[10]  = { 72, 64, 56, 48, 40, 32, 24, 16, 8, 0 };
  128.  
  129.  
  130.                                         /* this array shows the size of the */
  131.                                         /* 22V10-OLMCs ( AR and SP = 1 )    */
  132. int     OLMCSize22V10[12] = { 9, 11, 13, 15, 17, 17, 15, 13, 11, 9, 1, 1 };
  133.  
  134.                 /* The last two entries of the 22V10 arrays are for the   */
  135.                 /* AR and SP rows of the 22V10 GAL. This rows are not     */
  136.                 /* connected to an OLMC. But to keep the assembler as     */
  137.                 /* simple as possible, I introduced  two "OLMCs" for the  */
  138.                 /* AR and SP. The assembler treads them like real OLMCs.  */
  139.                 /* So don't become confused when OLMC number 11 and 12    */
  140.                 /* are used as inputs, outputs, pins... by the assembler. */
  141.                 /* These two OLMCs are just dummy-OLMCs.                  */
  142.  
  143.  
  144. UBYTE   PinNames[24][10], PinNamesOpt[26][10];
  145. UBYTE   PinDecNeg[24];
  146. UBYTE   ModeErrorStr[] = "Mode  x:  Pin xx";
  147. UBYTE   *pinnames;
  148.  
  149.  
  150. LONG    fsize;
  151. UBYTE   *fbuff;
  152.  
  153. int     num_of_pins, num_of_col, modus, gal_type;
  154. int     asmreadyflag;
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163. /******************************************************************************
  164. ** AssembleInputFile()
  165. *******************************************************************************
  166. ** input:   OpMode   ASSEMBLER: assemble source file and gererate JEDEC
  167. **                              structure
  168. **                   OPTIMIZER: assemble source file up to the Boolean
  169. **                              equations and return without generating the
  170. **                              JEDEC structure (a kind of syntax test)
  171. ** output:  0:    successful
  172. **          else: error or canceled
  173. **
  174. ** remarks: This function does assemble a *.pld file.
  175. ******************************************************************************/
  176.  
  177. int AssembleInputFile(int OpMode)
  178. {
  179.     UBYTE   chr;
  180.     UBYTE   *bool_start, *oldptr;
  181.     char    prevOp;
  182.     char    suffix_strn[MAX_SUFFIX_SIZE];
  183.     int     i, j, k, l, n, m;
  184.     int     max_chr, pass, pin_num, bool_linenum;
  185.     int     actOLMC, row_offset, newline, oldline;
  186.     int     suffix, start_row, max_row, num_of_olmcs;
  187.  
  188.  
  189.     m = YES;
  190.  
  191.     if (OpMode == ASSEMBLER)
  192.         m = AsmRequester();                 /* open options window */
  193.  
  194.     if (m)                                  /* load source file */
  195.     {
  196.         if (MyFileReq(AppStrings[MSG_LOAD_SOURCE].as_Str, ".pld", YES, LOAD))
  197.         {
  198.  
  199.             fsize = FileSize((UBYTE *)&path);
  200.  
  201.             switch (fsize)
  202.             {
  203.                 case -1L:
  204.                     ErrorReq(1);
  205.                     return(-1);
  206.                     break;
  207.  
  208.                 case -2L:
  209.                     ErrorReq(2);
  210.                     return(-2);
  211.                     break;
  212.  
  213.                 case 0L:
  214.                     ErrorReq(4);
  215.                     return(-4);
  216.                     break;
  217.             }
  218.  
  219.  
  220.             if ((fbuff = (UBYTE *)AllocMem(fsize, MEMF_PUBLIC)))
  221.             {
  222.  
  223.                 if ((ReadFile((UBYTE *)&path, fsize, fbuff)))
  224.                 {
  225.  
  226.                     PrintText(AppStrings[MSG_FILE_LOADED].as_Str, 1);
  227.  
  228.                     actptr  = fbuff;
  229.                     buffend = fbuff+fsize;
  230.                     linenum = 1;
  231.  
  232.                     for (n = 0; n < sizeof(Jedec); n++)
  233.                     {                            /* init. JEDEC structure */
  234.                         if (n < LOGIC22V10_SIZE)
  235.                             Jedec.GALLogic[n] = 1;         /* set fuses */
  236.                         else
  237.                             Jedec.GALLogic[n] = 0;         /* clear ACW... */
  238.                     }
  239.  
  240.  
  241.  
  242.                     for (n = 0; n < 12; n++)
  243.                     {                              /* clear OLMC structure */
  244.                         OLMC[n].Active   = 0;
  245.                         OLMC[n].PinType  = 0;
  246.                         OLMC[n].TriCon   = 0;
  247.                         OLMC[n].Clock    = 0;
  248.                         OLMC[n].ARST     = 0;
  249.                         OLMC[n].APRST    = 0;
  250.                         OLMC[n].FeedBack = 0;
  251.                     }
  252.  
  253.  
  254.                                         /*** get type of GAL ***/
  255.  
  256.                     if (!strncmp((char *)actptr, "GAL16V8", (size_t)7))
  257.                     {
  258.                         num_of_olmcs = 8;                  /* number of OLMCs */
  259.                         num_of_pins  = 20;                 /* number of pins  */
  260.                         num_of_col   = MAX_FUSE_ADR16 + 1; /* number of col.  */
  261.                         gal_type     = GAL16V8;
  262.  
  263.                         if ((*(actptr+7L) != ' ')  &&
  264.                             (*(actptr+7L) != 0x0A) &&
  265.                             (*(actptr+7L) != 0x09))
  266.                         {
  267.                             AsmError(1, 0);
  268.                             return(-1);
  269.                         }
  270.                     }
  271.                     else
  272.                         if (!strncmp((char *)actptr, "GAL20V8", (size_t)7))
  273.                         {
  274.                             num_of_olmcs = 8;                 /* num of OLMCs */
  275.                             num_of_pins  = 24;                /* num of pins  */
  276.                             num_of_col   = MAX_FUSE_ADR20 + 1;/* num of col   */
  277.                             gal_type     = GAL20V8;
  278.  
  279.                             if ((*(actptr+7L) != ' ')  &&
  280.                                 (*(actptr+7L) != 0x0A) &&
  281.                                 (*(actptr+7L) != 0x09))
  282.                             {
  283.                                 AsmError(1, 0);
  284.                                 return(-1);
  285.                             }
  286.                         }
  287.                         else
  288.                             if (!strncmp((char *)actptr, "GAL20RA10", (size_t)9))
  289.                             {
  290.                                 num_of_olmcs = 10;
  291.                                 num_of_pins  = 24;
  292.                                 num_of_col   = MAX_FUSE_ADR20RA10 + 1;
  293.                                 gal_type     = GAL20RA10;
  294.  
  295.                                 if ((*(actptr+9L) != ' ')  &&
  296.                                     (*(actptr+9L) != 0x0A) &&
  297.                                     (*(actptr+9L) != 0x09) )
  298.                                 {
  299.                                     AsmError(1, 0);
  300.                                     return(-1);
  301.                                 }
  302.                             }
  303.                             else
  304.                                 if (!strncmp((char *)actptr, "GAL22V10",
  305.                                     (size_t)8))
  306.                                 {
  307.                                     num_of_olmcs = 10;
  308.                                     num_of_pins  = 24;
  309.                                     num_of_col   = MAX_FUSE_ADR22V10 + 1;
  310.                                     gal_type     = GAL22V10;
  311.  
  312.                                     if ((*(actptr+8L) != ' ')  &&
  313.                                         (*(actptr+8L) != 0x0A) &&
  314.                                         (*(actptr+8L) != 0x09))
  315.                                     {
  316.                                         AsmError(1, 0);
  317.                                         return(-1);
  318.                                     }
  319.                                 }
  320.                                 else
  321.                                 {
  322.                                     AsmError(1, 0);
  323.                                     return(-1);
  324.                                 }
  325.  
  326.  
  327.                                 /*** get the leading 8 bytes of the second ***/
  328.                                 /*** line as signature                     ***/
  329.  
  330.  
  331.                 if (GetNextLine())                   /* end of file? */
  332.                 {
  333.                     AsmError(2, 0);                  /* yes, then error */
  334.                     return(-1);
  335.                 }
  336.                                             /* store signature in the */
  337.                 n = m = 0;                  /* JEDEC structure        */
  338.  
  339.  
  340.                                         /* end of signature: after eight */
  341.                                         /* characters, CR or TAB         */
  342.  
  343.  
  344.                 while((*actptr != 0x0A) && (*actptr != 0x09) && (n < 8))
  345.                 {
  346.                     chr = *actptr;
  347.  
  348.                     for (m = 0; m < 8; m++)
  349.                     Jedec.GALSig[n*8 + m] = (chr >> (7 - m)) & 0x1;
  350.  
  351.                     actptr++;                   /* increment pointer and */
  352.                     n++;                        /* character-counter     */
  353.  
  354.                     if (actptr>buffend)         /* end of file ?   */
  355.                     {                           /* yes, then error */
  356.  
  357.                         AsmError(2, 0);
  358.                         return(-1);
  359.                     }
  360.                 }
  361.  
  362.  
  363.                                 /*** get name of pins ***/
  364.  
  365.                                         /* clear flags for negations */
  366.                                         /* in the pin declaration    */
  367.  
  368.                 for (n = 0; n < 24; PinDecNeg[n++] = 0);
  369.  
  370.  
  371.  
  372.                 pinnames = &PinNames[0][0]; /*assembler: pin names in PinNames*/
  373.  
  374.                 if (OpMode == OPTIMIZER)    /*optimizer: pin names in PinNamesOpt*/
  375.                     pinnames = &PinNamesOpt[0][0];
  376.  
  377.                 asmreadyflag = 0;               /* set flag 'not assembled' */
  378.  
  379.                 GetNextLine();
  380.  
  381.             for (n = 0; n < num_of_pins; n++)
  382.             {
  383.                 if (GetNextChar())              /* unexpected end of file? */
  384.                 {                               /* yes, then error         */
  385.                     AsmError(2, 0);
  386.                     return(-1);
  387.                 }
  388.  
  389.                 m = 0;
  390.  
  391.                 chr = *actptr;                  /* get character */
  392.  
  393.                 if (IsNEG(chr))                 /* is there a negation? */
  394.                 {
  395.                     max_chr      = 10;
  396.                     PinDecNeg[n] = 1;           /* yes, then set flag */
  397.                 }
  398.                 else
  399.                     max_chr = 9;
  400.  
  401.                 if (!(isalpha(chr) || isdigit(chr) || IsNEG(chr)))
  402.                 {
  403.                     AsmError(5, 0);             /* is character a legal */
  404.                     return(-1);                 /* one?                 */
  405.                 }
  406.  
  407.                 k = 0;
  408.  
  409.                 while (isalpha(chr) || isdigit(chr) || IsNEG(chr))
  410.                 {
  411.                     if (IsNEG(chr) && k != 0)    /* check position of '/' */
  412.                     {
  413.                         AsmError(10, 0);         /* must be at the beginning */
  414.                         return(-1);              /* of the pin name          */
  415.                     }
  416.  
  417.                     k = 1;
  418.  
  419.                     actptr++;
  420.  
  421.                     if (IsNEG(chr) && (!(isalpha(*actptr) || isdigit(*actptr))))
  422.                     {
  423.                         AsmError(3, 0);
  424.                         return(-1);
  425.                     }
  426.  
  427.                     *(pinnames + n*10 + m) = chr;
  428.  
  429.                     m++;
  430.  
  431.                     chr = *actptr;
  432.  
  433.                     if (m == max_chr)          /* check number of characters */
  434.                     {                          /* in this pinname            */
  435.                         AsmError(4, 0);
  436.                         return(-1);            /* error: too many char. */
  437.                     }
  438.  
  439.                 }
  440.  
  441.                 *(pinnames+n*10+m) = 0;         /* mark end of string */
  442.  
  443.                 for (l = 0; l < n; l++)         /* pin name twice? */
  444.                 {
  445.                     if (strcmp((char *)pinnames+l*10, "NC"))
  446.                     {
  447.                         i = j = 0;
  448.  
  449.                         if (IsNEG(*(pinnames+l*10)))  /* skip negation sign */
  450.                             i = 1;
  451.  
  452.                         if (IsNEG(*(pinnames+n*10)))
  453.                             j = 1;
  454.  
  455.                         if (!strcmp((char *)(pinnames+l*10+i),
  456.                                     (char *)(pinnames+n*10+j)))
  457.                         {
  458.                             AsmError(9, 0);       /* pin name defined twice */
  459.                             return(-1);
  460.                         }
  461.                     }
  462.                 }
  463.                                                   /* is GND at the GND-pin? */
  464.                 if (!strcmp((char *)(pinnames + n*10), "GND"))
  465.                 {
  466.                     if (n+1 != num_of_pins/2)
  467.                     {
  468.                         AsmError(6, 0);
  469.                         return(-1);
  470.                     }
  471.                 }
  472.  
  473.                 if (n + 1 == num_of_pins/2)
  474.                 {
  475.                     if (strcmp((char *)(pinnames + n*10), "GND"))
  476.                     {
  477.                         AsmError(8, 0);
  478.                         return(-1);
  479.                     }
  480.                 }
  481.                                                 /* is VCC at the VCC pin? */
  482.                 if (!strcmp((char *)(pinnames + n*10), "VCC"))
  483.                 {
  484.                     if (n+1 != num_of_pins)
  485.                     {
  486.                         AsmError(6, 0);
  487.                         return(-1);
  488.                     }
  489.                 }
  490.  
  491.                 if (n + 1 == num_of_pins)
  492.                 {
  493.                     if (strcmp((char *)(pinnames + n*10), "VCC"))
  494.                     {
  495.                         AsmError(7, 0);
  496.                         return(-1);
  497.                     }
  498.                 }
  499.                                         /* AR and SP are key words for 22V10 */
  500.                                         /* they are not allowed in the pin */
  501.                                         /* declaration */
  502.                 if (gal_type == GAL22V10)
  503.                 {
  504.                     if (!strcmp((char *)(pinnames+n*10), "AR"))
  505.                     {
  506.                         AsmError(18, 0);
  507.                         return(-1);
  508.                     }
  509.  
  510.                     if (!strcmp((char *)(pinnames + n*10), "SP"))
  511.                     {
  512.                         AsmError(18, 0);
  513.                         return(-1);
  514.                     }
  515.                 }
  516.  
  517.             }
  518.  
  519.  
  520.             if (OpMode == OPTIMIZER)     /* if this routine is called from */
  521.                 return(0);               /* the optimizer, then finish     */
  522.  
  523.  
  524.  
  525. /* Boolean-Equations auswerten:
  526.    Dabei werden die Boolean-Equations zweimal untersucht. Beim ersten
  527.    Durchlauf werden die OLMC-Pins ausgewertet und die OLMC-Struktur ge-
  528.    füllt. Mit Hilfe dieser Struktur läßt sich auf dem notwendigen Modus
  529.    (1, 2 oder 3) schließen. Beim zweiten Durchlauf wird dann die
  530.    Fuse-Matrix erstellt.
  531. */
  532.  
  533.  
  534.     if (GetNextChar())                  /* end of file? */
  535.     {
  536.         AsmError(2, 0);
  537.         return(-1);
  538.     }
  539.  
  540.                                         /* are there any equations? */
  541.     if (!strncmp((char *)actptr, "DESCRIPTION", (size_t)11))
  542.     {
  543.         AsmError(33, 0);              /* no, then error */
  544.         return(-1);
  545.     }
  546.  
  547.  
  548.     bool_start   = actptr;            /* set pointer to the beginning of    */
  549.     bool_linenum = linenum;           /* the equations and save line number */
  550.  
  551.  
  552.     for (pass = 0; pass < 2; pass++)  /* this is a tow-pass-assembler */
  553.     {
  554.  
  555.         if (pass)                       /* 2. pass? => make ACW and get */
  556.         {                               /* the mode for 16V8,20V8 GALs  */
  557.             modus = 0;
  558.                                 /*** GAL16V8, GAL20V8 ***/
  559.  
  560.             if (gal_type == GAL16V8 || gal_type == GAL20V8)
  561.             {
  562.  
  563.                 for (n = 0; n < 8; n++)            /* examine all OLMCs */
  564.                 {
  565.                     if (OLMC[n].PinType == REGOUT) /* is there a registered  */
  566.                     {                              /* OLMC?, then GAL's mode */
  567.                         modus = MODE3;             /* is mode 3              */
  568.  
  569.                         Jedec.GALSYN = 0;      /* set SYN and AC0 for mode 3 */
  570.                         Jedec.GALAC0 = 1;
  571.  
  572.                         break;
  573.                     }
  574.                 }
  575.  
  576.  
  577.                 if (!modus)                     /* still no mode? */
  578.                 {
  579.                     for (n = 0; n < 8; n++)    /* examine all OLMCs */
  580.                     {
  581.                         if (OLMC[n].PinType == TRIOUT) /* is there a tristate */
  582.                         {                              /* OLMC?, then GAL's   */
  583.                             modus = MODE2;             /* mode is mode 2      */
  584.  
  585.                             Jedec.GALSYN = 1;      /* set SYN, AC0 for mode 2 */
  586.                             Jedec.GALAC0 = 1;
  587.  
  588.                             break;
  589.                         }
  590.                     }
  591.                 }
  592.  
  593.  
  594.                 if (!modus)           /* still no mode? */
  595.                 {
  596.                                       /* if there is a violation of mode 1, */
  597.                                       /* then use automatically mode 2      */
  598.                     for (n = 0; n < 8; n++)
  599.                     {
  600.                         if (OLMC[n].PinType == INPUT)
  601.                         {
  602.                             if (gal_type == GAL16V8)
  603.                             {
  604.                                 pin_num = n + 12;
  605.  
  606.                                 if (pin_num == 15 || pin_num == 16)
  607.                                 {
  608.                                     modus = MODE2;      /* mode 2 */
  609.  
  610.                                     Jedec.GALSYN = 1;   /* set SYN, AC0 bit */
  611.                                     Jedec.GALAC0 = 1;
  612.  
  613.                                     break;
  614.                                 }
  615.                             }
  616.  
  617.                             if (gal_type == GAL20V8)
  618.                             {
  619.                                 pin_num = n + 15;
  620.  
  621.                                 if (pin_num == 18 || pin_num == 19)
  622.                                 {
  623.                                     modus = MODE2;      /* mode 2 */
  624.  
  625.                                     Jedec.GALSYN = 1;   /* set SYN, AC0 bit */
  626.                                     Jedec.GALAC0 = 1;
  627.  
  628.                                     break;
  629.                                 }
  630.                             }
  631.                         }
  632.  
  633.                                 /* output and feedback? then mode 2 */
  634.  
  635.                         if (OLMC[n].PinType == COM_TRI_OUT && OLMC[n].FeedBack)
  636.                         {
  637.                             modus = MODE2;      /* mode 2 */
  638.  
  639.                             Jedec.GALSYN = 1;   /* set SYN,  AC0 bit */
  640.                             Jedec.GALAC0 = 1;
  641.  
  642.                             break;
  643.                         }
  644.                     }
  645.                 }
  646.  
  647.  
  648.                 if (!modus)             /* if there is still no mode */
  649.                 {                       /* defined, use mode 1 */
  650.                     modus = MODE1;
  651.  
  652.                     Jedec.GALSYN = 1;       /* set SYN and AC0 bit */
  653.                     Jedec.GALAC0 = 0;
  654.                 }
  655.  
  656.  
  657.  
  658.                 /* If GAL's mode is mode 1, use all OLMCs which type is   */
  659.                 /* not defined explicitly as combinational outputs.       */
  660.                 /* If GAL's mode is mode 2 or 3, use all OLMCs which type */
  661.                 /* is not defined explicitly as tristate output which is  */
  662.                 /* always enabled */
  663.  
  664.  
  665.                 for (n = 0; n < 8; n++)         /* examine all OLMCs */
  666.                 {
  667.                     if (OLMC[n].PinType == COM_TRI_OUT) /* is OLMC's type */
  668.                     {                                   /* definded expl. */
  669.                         if (modus == MODE1)  /* mode 1? then comb. output */
  670.                             OLMC[n].PinType = COMOUT;
  671.                         else
  672.                         {
  673.                             OLMC[n].PinType = TRIOUT;   /* mode 2, 3? then */
  674.                                                         /* tri. output     */
  675.  
  676.                             OLMC[n].TriCon  = TRI_VCC;  /* tristate control */
  677.                                                         /* = TRUE           */
  678.                         }
  679.                     }
  680.                 }
  681.         
  682.                                         /* make ACW; (SYN and AC0 are */
  683.                                         /* defined already) */
  684.  
  685.                 for (n = 0; n < PT_SIZE; n++)   /* set product term disable */
  686.                     Jedec.GALPT[n] = 1;
  687.  
  688.                                         /* get AC1 bits */
  689.                 for (n = 0; n < AC1_SIZE; n++)
  690.                 {
  691.                     if (OLMC[n].PinType == INPUT || OLMC[n].PinType == TRIOUT)
  692.                         Jedec.GALAC1[AC1_SIZE - 1 - n] = 1;
  693.                 }
  694.  
  695.                 for (n = 0; n < XOR_SIZE; n++)         /* get XOR bits */
  696.                 {
  697.                     if (((OLMC[n].PinType == COMOUT) ||
  698.                          (OLMC[n].PinType == TRIOUT) ||
  699.                          (OLMC[n].PinType == REGOUT)) &&
  700.                          (OLMC[n].Active  == ACTIVE_HIGH))
  701.                             Jedec.GALXOR[XOR_SIZE - 1 - n] = 1;
  702.                 }
  703.  
  704.             }
  705.  
  706.                                /*** GAL22V10 ***/
  707.  
  708.             if (gal_type == GAL22V10)
  709.             {
  710.  
  711.                 for (n = 0; n < 10; n++)
  712.                 {
  713.                                                 /* get XOR bits (S0) */
  714.                     if (OLMC[n].PinType == COM_TRI_OUT)  /* output can be */
  715.                         OLMC[n].PinType = TRIOUT;        /* tristate or   */
  716.                                                          /* register      */
  717.  
  718.                     if (((OLMC[n].PinType == COMOUT) ||
  719.                         (OLMC[n].PinType == TRIOUT) ||
  720.                         (OLMC[n].PinType == REGOUT)) &&
  721.                         (OLMC[n].Active  == ACTIVE_HIGH))
  722.                         Jedec.GALXOR[9 - n] = 1;
  723.  
  724.                                                 /* get AC1 bits (S1) */
  725.                     if (OLMC[n].PinType == INPUT || OLMC[n].PinType == TRIOUT)
  726.                         Jedec.GALS1[9 - n] = 1;
  727.                 }
  728.  
  729.             }
  730.  
  731.                                 /*** GAL20RA10 ***/
  732.  
  733.             if (gal_type == GAL20RA10)
  734.             {
  735.                                                 /* get XOR bits (S0) */
  736.                 for (n = 0; n < 10; n++)
  737.                 {
  738.                     if (OLMC[n].PinType == COM_TRI_OUT) /* output can be */
  739.                         OLMC[n].PinType = TRIOUT;       /* tristate or   */
  740.                                                         /* register      */
  741.  
  742.                     if (((OLMC[n].PinType == COMOUT) ||
  743.                          (OLMC[n].PinType == TRIOUT) ||
  744.                          (OLMC[n].PinType == REGOUT)) &&
  745.                          (OLMC[n].Active  == ACTIVE_HIGH))
  746.                         Jedec.GALXOR[9 - n] = 1;
  747.                 }
  748.             }
  749.  
  750.         }
  751.  
  752.  
  753.         actptr  = bool_start;
  754.  
  755.         linenum = bool_linenum;
  756.  
  757.         newline = linenum;
  758.  
  759.         goto label1;            /* Shit, don't blame me for the gotos.       */
  760.                                 /* I know, goto is a very bad command in C   */
  761.                                 /* and in the most other languages. But it   */
  762.                                 /* is very hard to remove them in this case. */
  763.  
  764. loop1:
  765.  
  766.         if (GetNextChar())                          /* end of file? */
  767.         {
  768.             AsmError(2, 0);
  769.             return(-1);
  770.         }
  771.  
  772.         suffix = SUFFIX_NON;
  773.  
  774.         if (*actptr == '.')         /* is there a suffix?       */
  775.         {                           /* yes, then get the string */
  776.             actptr++;
  777.  
  778.             if (gal_type == GAL22V10 &&
  779.                 (actPin.p_Pin == 24 || actPin.p_Pin == 25))
  780.             {
  781.                 AsmError(39, 0);                /* no suffix allowed at */
  782.                 return(-1);                     /* AR and SP */
  783.             }
  784.  
  785.  
  786.             n = 0;
  787.             while (isalpha(*actptr))            /* copy suffix string into */
  788.             {                                   /* suffix array            */
  789.                 if (n < MAX_SUFFIX_SIZE)
  790.                     suffix_strn[n++] = *actptr++;
  791.                 else
  792.                 {                               /* string too long, then */
  793.                     AsmError(13, 0);            /* unknown suffix        */
  794.                     return(-1);
  795.                 }
  796.             }
  797.  
  798.             suffix_strn[n] = 0;                 /* mark end of string */
  799.  
  800.             if (!strcmp(&suffix_strn[0], "T"))
  801.                 suffix = SUFFIX_T;
  802.             else
  803.                 if (!strcmp(&suffix_strn[0], "R"))
  804.                     suffix = SUFFIX_R;
  805.                 else
  806.                     if (!strcmp(&suffix_strn[0], "E"))
  807.                         suffix = SUFFIX_E;
  808.                     else
  809.                         if (!strcmp(&suffix_strn[0], "CLK"))
  810.                             suffix = SUFFIX_CLK;
  811.                         else
  812.                             if (!strcmp(&suffix_strn[0], "ARST"))
  813.                                 suffix = SUFFIX_ARST;
  814.                             else
  815.                                 if (!strcmp(&suffix_strn[0], "APRST"))
  816.                                     suffix = SUFFIX_APRST;
  817.                                 else
  818.                                 {
  819.                                     AsmError(13, 0);    /* unknown suffix */
  820.                                     return(-1);
  821.                                 }
  822.  
  823.                                         /* check whether suffix is */
  824.                                         /* allowed or not */
  825.             if (gal_type != GAL20RA10)
  826.             {
  827.                 switch (suffix)
  828.                 {
  829.                     case SUFFIX_CLK:
  830.                         AsmError(34, 0);            /* no .CLK allowed */
  831.                         return(-1);
  832.                         break;
  833.  
  834.                     case SUFFIX_ARST:
  835.                         AsmError(35, 0);            /* .ARST is not allowed */
  836.                         return(-1);
  837.                         break;
  838.  
  839.                     case SUFFIX_APRST:
  840.                         AsmError(36, 0);            /* .APRST is not allowed */
  841.                         return(-1);
  842.                         break;
  843.                 }
  844.             }
  845.  
  846.             if (GetNextChar())                      /* end of file? */
  847.             {
  848.                 AsmError(2, 0);
  849.                 return(-1);
  850.             }
  851.         }
  852.  
  853.  
  854.  
  855.         actOLMC = (int)actPin.p_Pin;                /* save offset of OLMC */
  856.  
  857.  
  858.         if (gal_type == GAL16V8)
  859.             actOLMC -= 12;
  860.         else
  861.             if (gal_type == GAL20V8)
  862.                 actOLMC -= 15;
  863.             else
  864.                 actOLMC -= 14;
  865.  
  866.  
  867.         row_offset = 0;                     /* offset for OR at OLMC*/
  868.  
  869.         prevOp     = 0;                     /* previous operator */
  870.  
  871.  
  872.         if (!pass)                      /* is this pass 1? */
  873.         {                               /* is pin a OLMC pin? */
  874.             if (((gal_type == GAL16V8) &&
  875.                  (actPin.p_Pin >= 12)  && (actPin.p_Pin <= 19)) ||
  876.                 ((gal_type == GAL20V8) &&
  877.                  (actPin.p_Pin >= 15) && (actPin.p_Pin <= 22)) ||
  878.                 ((gal_type == GAL22V10) &&
  879.                  (actPin.p_Pin >= 14) && (actPin.p_Pin <= DUMMY_OLMC12)) ||
  880.                 ((gal_type == GAL20RA10) &&
  881.                  (actPin.p_Pin >= 14) && (actPin.p_Pin <= 23)))
  882.             {
  883.  
  884.                 switch (gal_type)           /* get OLMC number */
  885.                 {
  886.                     case GAL16V8:
  887.                         n = actPin.p_Pin - 12;
  888.                         break;
  889.  
  890.                     case GAL20V8:
  891.                         n = actPin.p_Pin - 15;
  892.                         break;
  893.  
  894.                     case GAL22V10:
  895.                     case GAL20RA10:
  896.                         n = actPin.p_Pin - 14;
  897.                         break;
  898.                 }
  899.  
  900.  
  901.  
  902.                 switch (suffix)
  903.                 {
  904.  
  905.                     case SUFFIX_R:                /* output definition */
  906.                     case SUFFIX_T:
  907.                     case SUFFIX_NON:
  908.  
  909.                         if (!OLMC[n].PinType || OLMC[n].PinType == INPUT)
  910.                         {
  911.  
  912.                             if (actPin.p_Neg)        /* get pin's activation */
  913.                                 OLMC[n].Active = ACTIVE_LOW;
  914.                             else
  915.                                 OLMC[n].Active = ACTIVE_HIGH;
  916.  
  917.                             if (suffix == SUFFIX_T)
  918.                                 OLMC[n].PinType = TRIOUT;  /* tri. output */
  919.  
  920.                             if (suffix == SUFFIX_R)
  921.                                 OLMC[n].PinType = REGOUT;  /* reg. output */
  922.  
  923.                             if (suffix == SUFFIX_NON)    /* type of output is */
  924.                                 OLMC[n].PinType = COM_TRI_OUT; /* not defined */
  925.                                                                /* explicitly  */
  926.                         }
  927.                         else
  928.                         {
  929.                             if (gal_type == GAL22V10 && (n == 10 || n == 11))
  930.                             {
  931.                                 AsmError(40, 0);  /* AR or SP is defined */
  932.                                 return(-1);       /* twice               */
  933.                             }
  934.                             else
  935.                             {
  936.                                 AsmError(16, 0);  /* pin is defined twice as */
  937.                                 return(-1);       /* output                  */
  938.                             }
  939.                         }
  940.  
  941.                         break;
  942.  
  943.  
  944.  
  945.                 case SUFFIX_E:
  946.  
  947.                     if (actPin.p_Neg)       /* negation of the trisate */
  948.                     {                       /* control is not allowed */
  949.                         AsmError(19, 0);
  950.                         return(-1);
  951.                     }
  952.  
  953.                     if (OLMC[n].TriCon)     /* tri. control twice? */
  954.                     {                       /* yes, then error */
  955.                         AsmError(22, 0);
  956.                         return(-1);
  957.                     }
  958.  
  959.                     OLMC[n].TriCon = TRICON; /* set the flag that there is */
  960.                                              /* a tri. control equation    */
  961.  
  962.                     if (!OLMC[n].PinType || OLMC[n].PinType == INPUT)
  963.                     {
  964.                         AsmError(17, 0);     /* the sequence must be output  */
  965.                         return(-1);          /* followed by the tri. control */
  966.                     }
  967.  
  968.  
  969.                     if (OLMC[n].PinType == REGOUT &&
  970.                         (gal_type == GAL16V8 || gal_type == GAL20V8))
  971.                     {
  972.                         AsmError(23, 0);  /* GAL16V8/20V8: tristate control */
  973.                         return(-1);       /* for reg. output is not allowed */
  974.                     }
  975.  
  976.  
  977.                     if (OLMC[n].PinType == COM_TRI_OUT)
  978.                     {                                   /* no tristate .T? */
  979.                         AsmError(24, 0);                /* then error      */
  980.                         return(-1);
  981.                     }
  982.  
  983.                     break;
  984.  
  985.  
  986.  
  987.                case SUFFIX_CLK:
  988.  
  989.                     if (actPin.p_Neg)           /* negation of the .CLK   */
  990.                     {                           /* control is not allowed */
  991.                         AsmError(19, 0);
  992.                         return(-1);
  993.                     }
  994.  
  995.                     if (OLMC[n].PinType == NOTUSED)
  996.                     {
  997.                         AsmError(42, 0);        /* sequence must be: output */
  998.                         return(-1);             /* def., .CLK definition */
  999.                     }
  1000.  
  1001.                     if (OLMC[n].Clock)
  1002.                     {                           /* is .CLK defined twice? */
  1003.                         AsmError(45, 0);        /* yes, then error */
  1004.                         return(-1);
  1005.                     }
  1006.  
  1007.                     OLMC[n].Clock = 1;          /* set flag that there is */
  1008.                                                 /* a .CLK equation        */
  1009.                     if (OLMC[n].PinType != REGOUT)
  1010.                     {
  1011.                         AsmError(48, 0);        /* no .CLK allowed when     */
  1012.                         return(-1);             /* output is not registered */
  1013.                     }
  1014.  
  1015.                     break;
  1016.         
  1017.  
  1018.  
  1019.                 case SUFFIX_ARST:
  1020.  
  1021.                     if (actPin.p_Neg)
  1022.                     {                           /* negation of the .ARST  */
  1023.                         AsmError(19, 0);        /* control is not allowed */
  1024.                         return(-1);
  1025.                     }
  1026.  
  1027.                     if (OLMC[n].PinType == NOTUSED)
  1028.                     {
  1029.                         AsmError(43, 0);        /* sequence must be: output */
  1030.                         return(-1);             /* def., .ARST definition   */
  1031.                     }
  1032.  
  1033.                     if (OLMC[n].ARST)
  1034.                     {                           /* is .ARST defined twice? */
  1035.                         AsmError(46, 0);        /* yes, then error         */
  1036.                         return(-1);
  1037.                     }
  1038.  
  1039.                     OLMC[n].ARST = 1;           /* set flag that there is */
  1040.                                                 /* a .ARST equation       */
  1041.                     if (OLMC[n].PinType != REGOUT)
  1042.                     {
  1043.                         AsmError(48, 0);        /* no .CLK allowed when     */
  1044.                         return(-1);             /* output is not registered */
  1045.                     }
  1046.  
  1047.                     break;
  1048.  
  1049.  
  1050.  
  1051.                 case SUFFIX_APRST:
  1052.  
  1053.                     if (actPin.p_Neg)
  1054.                     {                           /* negation of the .APRST */
  1055.                         AsmError(19, 0);        /* control is not allowed */
  1056.                         return(-1);
  1057.                     }
  1058.  
  1059.                     if (OLMC[n].PinType == NOTUSED)
  1060.                     {
  1061.                         AsmError(44, 0);        /* sequence must be: output */
  1062.                         return(-1);             /* def., .APRST definition  */
  1063.                     }
  1064.  
  1065.                     if (OLMC[n].APRST)
  1066.                     {                           /* is .APRST defined twice? */
  1067.                         AsmError(47, 0);        /* yes, then error          */
  1068.                         return(-1);
  1069.                     }
  1070.  
  1071.                     OLMC[n].APRST = 1;          /* set flag that there is */
  1072.                                                 /* a .APRST equation      */
  1073.                     if (OLMC[n].PinType != REGOUT)
  1074.                     {
  1075.                         AsmError(48, 0);        /* no .CLK allowed when     */
  1076.                         return(-1);             /* output is not registered */
  1077.                     }
  1078.  
  1079.                     break;
  1080.                 }
  1081.  
  1082.             }
  1083.             else
  1084.             {
  1085.                 AsmError(15, 0);                /* pin can't be programmed */
  1086.                 return(-1);                     /* as output               */
  1087.             }
  1088.         }
  1089.  
  1090.  
  1091.  
  1092.  
  1093.         switch (gal_type)
  1094.         {                                       /* get first the row of the */
  1095.             case GAL16V8:                       /* OLMC and the number of   */
  1096.             case GAL20V8:                       /* rows which areavailable  */
  1097.                 start_row = ToOLMC[actOLMC];
  1098.                 max_row   = 8;
  1099.                 break;
  1100.  
  1101.             case GAL22V10:
  1102.                 start_row = ToOLMC22V10[actOLMC];
  1103.                 max_row   = OLMCSize22V10[actOLMC];
  1104.                 break;
  1105.  
  1106.             case GAL20RA10:
  1107.                 start_row = ToOLMC20RA10[actOLMC];
  1108.                 max_row   = 8;
  1109.                 break;
  1110.         }
  1111.  
  1112.  
  1113.  
  1114.  
  1115.         if (*actptr != '=')                     /* '=' ?          */
  1116.         {                                       /* no, then error */
  1117.             AsmError(14, 0);
  1118.             return(-1);
  1119.         }
  1120.  
  1121. loop2:
  1122.  
  1123.         actptr++;
  1124.  
  1125.         if (GetNextChar())
  1126.         {                                       /* end of file?    */
  1127.             AsmError(2, 0);                     /* yes, then error */
  1128.             return(-1);
  1129.         }
  1130.  
  1131.         oldptr = actptr;                            /* save pointer */
  1132.  
  1133.         IsPinName(pinnames, num_of_pins);
  1134.  
  1135.         if (gal_type == GAL22V10 && !actPin.p_Pin)
  1136.         {                               /* AR and SP is not allowed */
  1137.             Is_AR_SP(oldptr);           /* in terms of an equation  */
  1138.  
  1139.             if (actPin.p_Pin)
  1140.             {                           /* when used, then error */
  1141.                 AsmError(31, 0);
  1142.                 return(-1);
  1143.             }
  1144.         }
  1145.  
  1146.  
  1147.         if (!actPin.p_Pin)
  1148.         {                                   /* pin name?      */
  1149.             AsmError(11, 0);                /* no, then error */
  1150.             return(-1);
  1151.         }
  1152.  
  1153.  
  1154.         if (actPin.p_Pin == NC_PIN)
  1155.         {               /* NC used as pin name? */
  1156.             AsmError(12, 0);                          /* yes, then error */
  1157.             return(-1);
  1158.         }
  1159.  
  1160.  
  1161.         if (IsNEG(*(pinnames+(long)((actPin.p_Pin - 1)*10))))
  1162.             actPin.p_Neg = !actPin.p_Neg;       /* consider negation in the */
  1163.                                                 /* pin declartion           */
  1164.  
  1165.         oldline = linenum;
  1166.  
  1167.         if (GetNextChar())
  1168.         {                                       /* end of file?    */
  1169.             AsmError(2, 0);                     /* yes, then error */
  1170.             return(-1);
  1171.         }
  1172.  
  1173.         newline = linenum;
  1174.  
  1175.         linenum = oldline;
  1176.  
  1177.  
  1178.         if (!pass)                              /* is this pass 1?*/
  1179.         {
  1180.             if (((gal_type == GAL16V8) &&       /* is this pin an OLMC pin? */
  1181.                  (actPin.p_Pin >= 12) && (actPin.p_Pin <= 19)) ||
  1182.                 ((gal_type == GAL20V8) &&
  1183.                  (actPin.p_Pin >= 15) && (actPin.p_Pin <= 22)) ||
  1184.                 ((gal_type == GAL22V10) &&
  1185.                  (actPin.p_Pin >= 14) && (actPin.p_Pin <= DUMMY_OLMC12)) ||
  1186.                 ((gal_type == GAL20RA10) &&
  1187.                  (actPin.p_Pin >= 14) && (actPin.p_Pin <= 23)) )
  1188.             {
  1189.  
  1190.  
  1191.                 switch (gal_type)                        /* get OLMC number */
  1192.                 {
  1193.                     case GAL16V8:
  1194.                         n = actPin.p_Pin - 12;
  1195.                         break;
  1196.  
  1197.                     case GAL20V8:
  1198.                         n = actPin.p_Pin - 15;
  1199.                         break;
  1200.  
  1201.                     case GAL22V10:
  1202.                     case GAL20RA10:
  1203.                         n = actPin.p_Pin - 14;
  1204.                         break;
  1205.                 }
  1206.  
  1207.  
  1208.  
  1209.                 if (!OLMC[n].PinType)            /* is OLMC's type already */
  1210.                     OLMC[n].PinType = INPUT;     /* defined? no, then use  */
  1211.                                                  /* it as input            */
  1212.                 OLMC[n].FeedBack = YES; /* if a OLMC pin is used within an */
  1213.             }                           /* equation, a feedback is needed  */
  1214.         }
  1215.  
  1216.                               /* in pass 2 we have to make the fuse matrix */
  1217.         if (pass)
  1218.         {
  1219.    
  1220.             switch (gal_type)                /* get row offset */
  1221.             {
  1222.                 case GAL16V8:
  1223.                 case GAL20V8:
  1224.  
  1225.                     if (suffix == SUFFIX_E)   /* when tristate control use */
  1226.                         row_offset = 0;       /* first row (=> offset = 0) */
  1227.                     else
  1228.                         if (!row_offset)  /*is offset of rows still equal 0?*/
  1229.                             if (modus != MODE1 &&
  1230.                                 OLMC[actOLMC].PinType != REGOUT)
  1231.                                 row_offset = 1;    /* then init. row-offset */
  1232.  
  1233.                     break;
  1234.  
  1235.                 case GAL22V10:
  1236.  
  1237.                     if (suffix == SUFFIX_E)    /* enable is the first row */
  1238.                         row_offset = 0;        /* of the OLMC             */
  1239.                     else
  1240.                     {
  1241.                         if (actOLMC == 10 || actOLMC == 11)
  1242.                             row_offset = 0;     /* AR, SP?, then no offset */
  1243.                         else
  1244.                             if (!row_offset)     /* output starts at the     */
  1245.                                 row_offset = 1;  /* second row => offset = 1 */
  1246.                     }
  1247.  
  1248.                     break;
  1249.  
  1250.                 case GAL20RA10:
  1251.                     switch (suffix)
  1252.                     {
  1253.                         case SUFFIX_E:         /* enable is the first row */
  1254.                             row_offset = 0;    /* of the OLMC             */
  1255.                             break;
  1256.  
  1257.                         case SUFFIX_CLK:       /* Clock is the second row */
  1258.                             row_offset = 1;    /* of the OLMC             */
  1259.                             break;
  1260.  
  1261.                         case SUFFIX_ARST:      /* AReset is the third row */
  1262.                             row_offset = 2;    /* of the OLMC             */
  1263.                             break;
  1264.  
  1265.                         case SUFFIX_APRST:     /* APreset is the fourth row */
  1266.                             row_offset = 3;    /* of the OLMC               */
  1267.                             break;
  1268.  
  1269.                         default:                  /* output equation starts */
  1270.                             if (row_offset <= 3)  /* at the fifth row       */
  1271.                                 row_offset = 4;
  1272.                     }
  1273.                     break;
  1274.             }
  1275.  
  1276.             pin_num = actPin.p_Pin;
  1277.  
  1278.  
  1279.                                 /* is there a valuation of GAL's mode? */
  1280.  
  1281.             if (gal_type == GAL16V8 || gal_type == GAL20V8)
  1282.             {
  1283.  
  1284.                 if (modus == MODE2)               /* valuation of mode 2? */
  1285.                 {
  1286.                     if (gal_type == GAL16V8 && (pin_num == 12 || pin_num == 19))
  1287.                     {
  1288.                         AsmError(20, 0);
  1289.                         return(-1);
  1290.                     }
  1291.  
  1292.                     if (gal_type == GAL20V8 && (pin_num == 15 || pin_num == 22))
  1293.                     {
  1294.                         AsmError(21, 0);
  1295.                         return(-1);
  1296.                     }
  1297.                 }
  1298.  
  1299.                 if (modus == MODE3)                /* valuation of mode 3? */
  1300.                 {
  1301.                     if (gal_type == GAL16V8 && (pin_num == 1 || pin_num == 11))
  1302.                     {
  1303.                         AsmError(26, 0);
  1304.                         return(-1);
  1305.                     }
  1306.  
  1307.                     if (gal_type == GAL20V8 && (pin_num == 1 || pin_num == 13))
  1308.                     {
  1309.                         AsmError(27, 0);
  1310.                         return(-1);
  1311.                     }
  1312.                 }
  1313.             }
  1314.  
  1315.             if (gal_type == GAL20RA10)       /* valuation of 20RA10? */
  1316.             {
  1317.                 if (pin_num == 1)               /* pin 1 is reserved for */
  1318.                 {                               /* /PL (preload)         */
  1319.                     AsmError(37, 0);
  1320.                     return(-1);
  1321.                 }
  1322.  
  1323.                 if (pin_num == 13)
  1324.                 {                               /* pin 13 is reserved for */
  1325.                     AsmError(38, 0);            /* /OE (output enable)    */
  1326.                     return(-1);
  1327.                 }
  1328.             }
  1329.  
  1330.  
  1331.                                           /* if GND, set row equal 0 */
  1332.             if (pin_num == num_of_pins || pin_num == num_of_pins/2)
  1333.             {
  1334.                 if (actPin.p_Neg)
  1335.                 {                         /* /VCC and /GND are not allowed */
  1336.                     AsmError(25, 0);
  1337.                     return(-1);
  1338.                 }
  1339.  
  1340.                 if (!prevOp && !IsAND(*actptr) && !IsOR(*actptr))
  1341.                 {
  1342.  
  1343.                     if (pin_num == num_of_pins/2)
  1344.                     {
  1345.                         m = (start_row + row_offset) * num_of_col;
  1346.                                                       /* set row equal 0 */
  1347.                         for (n = m; n < m+num_of_col; Jedec.GALLogic[n++] = 0);
  1348.  
  1349.                     }
  1350.                 }
  1351.                 else
  1352.                 {
  1353.                     AsmError(28, 0);
  1354.                     return(-1);
  1355.                 }
  1356.             }
  1357.             else
  1358.             {
  1359.  
  1360.                 if (suffix == SUFFIX_E || suffix == SUFFIX_CLK ||
  1361.                     suffix == SUFFIX_ARST || suffix == SUFFIX_APRST ||
  1362.                     (gal_type == GAL22V10 && (actOLMC == 10 || actOLMC == 11)))
  1363.                 {
  1364.  
  1365.                     if (IsOR(prevOp))
  1366.                     {                           /* max. one product term   */
  1367.                         AsmError(29, 0);        /* for CLK, ARST, APRST, E */
  1368.                         return(-1);             /* and 22V10: AR, SP       */
  1369.                     }
  1370.  
  1371.                     SetAND(start_row + row_offset, pin_num, actPin.p_Neg);
  1372.                 }
  1373.                 else
  1374.                 {
  1375.                     if (IsOR(prevOp))
  1376.                     {                             /* OR operation? yes, then */
  1377.                         row_offset++;             /* take the next row       */
  1378.  
  1379.                         if (row_offset == max_row)
  1380.                         {        /* too many ORs?*/
  1381.                             AsmError(30, 0);
  1382.                             return(-1);
  1383.                         }
  1384.                     }
  1385.                                                            /* set ANDs */
  1386.                     SetAND(start_row + row_offset, pin_num, actPin.p_Neg);
  1387.                 }
  1388.             }
  1389.  
  1390.  
  1391.                                             /* are there any more terms? */
  1392.             if (!IsOR(*actptr) && !IsAND(*actptr) && suffix != SUFFIX_E &&
  1393.                 suffix != SUFFIX_CLK && suffix != SUFFIX_ARST &&
  1394.                 suffix != SUFFIX_APRST)
  1395.             {
  1396.                                                     /* no?, then set unused */
  1397.                 row_offset++;                       /* rows of the OLMX     */
  1398.                                                     /* equal 0              */
  1399.                 if (row_offset != max_row)
  1400.                 {
  1401.                     m = (start_row + row_offset) * num_of_col;
  1402.  
  1403.                     for (n = m; n < m + (max_row - row_offset)*num_of_col; n++)
  1404.                         Jedec.GALLogic[n] = 0;
  1405.  
  1406.                 }
  1407.             }
  1408.         }
  1409.  
  1410.  
  1411.         linenum = newline;
  1412.  
  1413.         if (IsOR(*actptr) || IsAND(*actptr))
  1414.         {
  1415.             prevOp = *actptr;
  1416.             goto loop2;
  1417.         }
  1418.  
  1419.         if (strncmp((char *)actptr, "DESCRIPTION", (size_t)11))
  1420.         {
  1421.  
  1422. label1:
  1423.             linenum = newline;
  1424.  
  1425.             oldptr = actptr;
  1426.  
  1427.             IsPinName(pinnames, num_of_pins);
  1428.  
  1429.             if (gal_type == GAL22V10 && !actPin.p_Pin)
  1430.             {                                       /* no pin name? then  */
  1431.                 Is_AR_SP(oldptr);                   /* check whether name */
  1432.                                                     /* is AR or SP        */
  1433.                 if (actPin.p_Pin && actPin.p_Neg)
  1434.                 {                                   /* but no negation of */
  1435.                     AsmError(32, 0);                /* AR or SP           */
  1436.                     return(-1);
  1437.                 }
  1438.             }
  1439.               
  1440.             if (!actPin.p_Pin)
  1441.             {                                       /* pin name?      */
  1442.                 AsmError(11, 0);                    /* no, then error */
  1443.                 return(-1);
  1444.             }
  1445.  
  1446.             if (actPin.p_Pin == NC_PIN)
  1447.             {                                       /* NC used as pin name? */
  1448.                 AsmError(12, 0);                    /* yes, then error      */
  1449.                 return(-1);
  1450.             }
  1451.  
  1452.             if (IsNEG(*(pinnames+(long)((actPin.p_Pin-1)*10))))
  1453.                 actPin.p_Neg = !actPin.p_Neg; /* negation at pin declaration */
  1454.  
  1455.             goto loop1;
  1456.  
  1457.         }
  1458.  
  1459.     }
  1460.  
  1461.  
  1462.                         /* set fuse matrix of unused OLMCs and of OLMCs */
  1463.                         /* which are programmed as input equal 0        */
  1464.  
  1465.     for (n = 0; n < num_of_olmcs; n++)
  1466.     {
  1467.         if (OLMC[n].PinType == NOTUSED || OLMC[n].PinType == INPUT)
  1468.         {
  1469.  
  1470.             switch (gal_type)
  1471.             {                           /* get first row of the     */
  1472.                 case GAL16V8:           /* OLMC and the number of   */
  1473.                 case GAL20V8:           /* rows which are available */
  1474.                     l = ToOLMC[n];
  1475.                     i = 8;
  1476.                     break;
  1477.  
  1478.                 case GAL22V10:
  1479.                     l = ToOLMC22V10[n];
  1480.                     i = OLMCSize22V10[n];
  1481.                     break;
  1482.  
  1483.                 case GAL20RA10:
  1484.                     l = ToOLMC20RA10[n];
  1485.                     i = 8;
  1486.                     break;
  1487.             }
  1488.  
  1489.             l = l * num_of_col;
  1490.  
  1491.             m = l + i * num_of_col;
  1492.  
  1493.             for (k = l; k < m; k++)
  1494.                 Jedec.GALLogic[k] = 0;
  1495.         }
  1496.     }
  1497.  
  1498.  
  1499.     if (gal_type == GAL22V10)
  1500.     {                                   /* if AR or SP is not defined,   */
  1501.                                         /* set corresponding row equal 0 */
  1502.         if (!OLMC[10].PinType)                  /* set row of AR equal 0 */
  1503.             for (n = 0; n < num_of_col; Jedec.GALLogic[n++] = 0);
  1504.  
  1505.         if (!OLMC[11].PinType)                         /* set row of SP equal 0 */
  1506.             for (n = 5764; n < 5764 + num_of_col; Jedec.GALLogic[n++] = 0);
  1507.     }
  1508.  
  1509.  
  1510.     if (gal_type == GAL20RA10)
  1511.     {                                           /* set unused CLK, ARST */
  1512.                                                 /* and APRST equal 0    */
  1513.         for (n = 0; n < num_of_olmcs; n++)      /* examine all OLMCs    */
  1514.         {
  1515.             if (OLMC[n].PinType != NOTUSED)     /* is OLMC used? */
  1516.             {
  1517.                 if (OLMC[n].PinType == REGOUT && !OLMC[n].Clock)
  1518.                 {
  1519.                     AsmError(41, n + 14);       /* register output        */
  1520.                     return(-1);                 /* needs clock definition */
  1521.                 }
  1522.  
  1523.                 if (!OLMC[n].Clock)
  1524.                 {                                      /* is clock unused? */
  1525.                     l = (ToOLMC20RA10[n] + 1) * num_of_col;  /* then clear */
  1526.                                                              /* the row    */
  1527.                     for (k = l; k < l + num_of_col; k++)
  1528.                         Jedec.GALLogic[k] = 0;
  1529.                 }
  1530.  
  1531.                 if (OLMC[n].PinType == REGOUT)
  1532.                 {
  1533.                     if (!OLMC[n].ARST)
  1534.                     {                  /* is ARST unused? */
  1535.                         l = (ToOLMC20RA10[n] + 2) * num_of_col;
  1536.  
  1537.                         for (k = l; k < l + num_of_col; k++)
  1538.                             Jedec.GALLogic[k] = 0;
  1539.                     }
  1540.  
  1541.                     if (!OLMC[n].APRST)
  1542.                     {                               /* is APRST unused? */
  1543.                         l = (ToOLMC20RA10[n] + 3) * num_of_col;
  1544.  
  1545.                         for (k = l; k < l + num_of_col; k++)
  1546.                             Jedec.GALLogic[k] = 0;
  1547.                     }
  1548.                 }
  1549.  
  1550.             }
  1551.  
  1552.         }
  1553.  
  1554.     }
  1555.  
  1556.  
  1557. /* now the JEDEC structure is ready */
  1558. /* (be happy, it was a hard task)   */
  1559.  
  1560.  
  1561.  
  1562.                     asmreadyflag = 1; /* set flag, so that we can see that  */
  1563.                                       /* this file is assembled succesfully */
  1564.  
  1565.                     FreeMem(fbuff, fsize); /* free buffer of the *.pld-file */
  1566.  
  1567.  
  1568.  
  1569.                     if (Config.AutoGAL == YES)
  1570.                     {                         /*redraw the symbolic GAL and */
  1571.                         SetGALType(gal_type); /*print the names of the GAL's*/
  1572.                                               /*pins                        */
  1573.                         PrintPinNames();
  1574.                     }
  1575.  
  1576.  
  1577.                                       /*** now make the selected files ***/
  1578.  
  1579.                     if (Config.GenJedec == YES)
  1580.                         if (MyFileReq(AppStrings[MSG_WRITE_JED].as_Str, ".jed",
  1581.                             !Config.AutoSave, SAVE))
  1582.                             WriteJedecFile(gal_type);
  1583.  
  1584.                     if (Config.GenFuse == YES)
  1585.                         WriteFuseFile();
  1586.  
  1587.                     if (Config.GenChip == YES)
  1588.                         WriteChipFile();
  1589.  
  1590.                     if (Config.GenPin == YES)
  1591.                         WritePinFile();
  1592.  
  1593.                     PrintText(AppStrings[MSG_FILE_ASM].as_Str, 1);
  1594.                         return(0);                 /* there was no error */
  1595.  
  1596.                 }
  1597.                 else
  1598.                 {
  1599.                     ErrorReq(3);                          /* read error */
  1600.                     FreeMem(fbuff,fsize);                 /* can't load source file */
  1601.                     return(-2);
  1602.                 }
  1603.             }
  1604.             else
  1605.             {
  1606.                 ErrorReq(2);                            /* no more free memory */
  1607.                 return(-2);
  1608.             }
  1609.         }
  1610.         else
  1611.             return(-1);                       /* file requester canceled */
  1612.     }
  1613.     else
  1614.         return(-1);                         /* assembler requester canceled */
  1615. }
  1616.  
  1617.  
  1618.  
  1619.  
  1620.  
  1621. /******************************************************************************
  1622. ** SetAND()
  1623. *******************************************************************************
  1624. ** input:   row         row in which the AND should be set
  1625. **          pinnum      pin which should be ANDed
  1626. **          negation    0: pin without negation
  1627. **                      1: pin with negation sign (/)
  1628. **
  1629. ** output:  none
  1630. **
  1631. ** remarks: sets an AND (=0) in the fuse matrix
  1632. ******************************************************************************/
  1633.  
  1634. void SetAND(int row, int pinnum, int negation)
  1635. {
  1636.     int column;
  1637.  
  1638.     switch (gal_type)
  1639.     {
  1640.         case GAL16V8:
  1641.             if (modus == MODE1)
  1642.                 column = PinToFuse16Mode1[pinnum - 1];
  1643.             if (modus == MODE2)
  1644.                 column = PinToFuse16Mode2[pinnum - 1];
  1645.             if (modus == MODE3)
  1646.                 column = PinToFuse16Mode3[pinnum - 1];
  1647.             break;
  1648.  
  1649.         case GAL20V8:
  1650.             if (modus == MODE1)
  1651.                 column  =  PinToFuse20Mode1[pinnum - 1];
  1652.             if (modus == MODE2)
  1653.                 column  =  PinToFuse20Mode2[pinnum - 1];
  1654.             if (modus == MODE3)
  1655.                 column  =  PinToFuse20Mode3[pinnum - 1];
  1656.             break;
  1657.  
  1658.         case GAL22V10:
  1659.             column  =  PinToFuse22V10[pinnum - 1];
  1660.  
  1661.                                     /* is it a registered OLMC pin?   */
  1662.                                     /* yes, then correct the negation */
  1663.             if ((pinnum >= 14 && pinnum <= 23) && !Jedec.GALS1[23 - pinnum])
  1664.             {
  1665.                 negation = negation ? 0 : 1;
  1666.             }
  1667.  
  1668.             break;
  1669.  
  1670.         case GAL20RA10:
  1671.             column  =  PinToFuse20RA10[pinnum - 1];
  1672.             break;
  1673.     }
  1674.  
  1675.     Jedec.GALLogic[row*num_of_col + column + negation] = 0;
  1676.  
  1677. }
  1678.  
  1679.  
  1680.  
  1681.  
  1682.  
  1683. /******************************************************************************
  1684. ** IsPinName()
  1685. *******************************************************************************
  1686. ** input:   *pinnames   pointer to the pinnames array
  1687. **          numofpins   number of pins (20 or 24, depends on the type of GAL)
  1688. **
  1689. **  global: actptr          pointer to the first character of the pinname
  1690. **          actPin.p_Pin:   number of pin or NC_PIN; 0: no pin
  1691. **          actPin.p_Neg:   pinname with '/' = 1;  without '/' = 0
  1692. **
  1693. ** output:  none
  1694. **
  1695. ** remarks: This function tests whether actptr points to a pinname or not
  1696. ******************************************************************************/
  1697.  
  1698. void IsPinName(UBYTE *pinnames, int numofpins)
  1699. {
  1700.     int     i, k, n;
  1701.     UBYTE   *oldactptr;
  1702.  
  1703.  
  1704.     actPin.p_Neg = 0;                   /* install structure for pin */
  1705.     actPin.p_Pin = 0;
  1706.  
  1707.     if (IsNEG(*actptr))
  1708.     {                                   /* negation? */
  1709.         actptr++;
  1710.         actPin.p_Neg = 1;
  1711.     }
  1712.  
  1713.     n = 0;                                /* get length of pin name */
  1714.  
  1715.     oldactptr = actptr;
  1716.  
  1717.     while (isalpha(*actptr) || isdigit(*actptr))
  1718.     {
  1719.         actptr++;
  1720.         n++;
  1721.     }
  1722.  
  1723.     if (n)
  1724.         if ((n == 2 ) && !strncmp((char *)oldactptr, "NC", (size_t)2))
  1725.             actPin.p_Pin = NC_PIN;                      /* NC pin*/
  1726.         else
  1727.             for (k = 0; k < numofpins; k++)
  1728.             {                           /* examine whole list of pin names */
  1729.                 i = 0;
  1730.  
  1731.                 if (IsNEG(*(pinnames+k*10)))
  1732.                     i = 1;
  1733.  
  1734.                                          /* are the string sizes equal? */
  1735.                 if (n == strlen((char *)(pinnames+k*10+i)))
  1736.                     if (!(strncmp((char *)oldactptr, (char *)(pinnames+k*10+i),
  1737.                           (size_t)n)))   /* yes, then compare these strings */
  1738.                 {
  1739.                     actPin.p_Pin = k + 1;
  1740.                     break;
  1741.                 }
  1742.             }
  1743. }
  1744.  
  1745.  
  1746.  
  1747.  
  1748.  
  1749. /******************************************************************************
  1750. ** Is_AR_SP()
  1751. *******************************************************************************
  1752. ** input:   *ptr    pointer to the first character of the pinname
  1753. **
  1754. ** output:  none
  1755. **          global  actPin.p_Pin: 23: AR, 24: SP, 0: no AR, SP
  1756. **                  actPin.p_Neg: pinname with '/' = 1;  without '/' = 0
  1757. **
  1758. ** remarks: This function tests whether actptr points to a AR or SP
  1759. ******************************************************************************/
  1760.  
  1761. void Is_AR_SP(UBYTE *ptr)
  1762. {
  1763.     int     n;
  1764.     UBYTE   *oldptr;
  1765.  
  1766.  
  1767.     actPin.p_Neg = 0;                     /* install structure for pin */
  1768.     actPin.p_Pin = 0;
  1769.  
  1770.     if (IsNEG(*ptr))
  1771.     {                    /* negation? */
  1772.         ptr++;
  1773.         actPin.p_Neg = 1;
  1774.     }
  1775.  
  1776.     n = 0;                                /* get length of pin name */
  1777.  
  1778.     oldptr = ptr;
  1779.  
  1780.     while (isalpha(*ptr) || isdigit(*ptr))
  1781.     {
  1782.         ptr++;
  1783.         n++;
  1784.     }
  1785.                         /* assign AR to "OLMC 11" ("pin 24") and */
  1786.     if (n)              /* assign SP to "OLMC 12" ("pin 25")     */
  1787.     {
  1788.         if ((n == 2 ) && !strncmp((char *)oldptr, "AR", (size_t)2))
  1789.             actPin.p_Pin = DUMMY_OLMC11;
  1790.  
  1791.         if ((n == 2 ) && !strncmp((char *)oldptr, "SP", (size_t)2))
  1792.             actPin.p_Pin = DUMMY_OLMC12;
  1793.     }
  1794. }
  1795.  
  1796.  
  1797.  
  1798.  
  1799.  
  1800. /******************************************************************************
  1801. ** GetNextChar()
  1802. *******************************************************************************
  1803. ** input:   none
  1804. **
  1805. ** output:  0: character found, actptr points to it
  1806. **          1: no character found
  1807. **
  1808. ** remarks: searchs the next character which is no comment, space, TAB, LF
  1809. ******************************************************************************/
  1810.  
  1811. int GetNextChar(void)
  1812. {
  1813.  
  1814.     for(;;)
  1815.     {
  1816.         switch (*actptr)
  1817.         {
  1818.             case 0x0A:                           /* LineFeed */
  1819.                 actptr++;
  1820.                 linenum++;
  1821.                 break;
  1822.  
  1823.             case ' ':                            /* space */
  1824.             case 0x09:                           /* TAB   */
  1825.                 actptr++;
  1826.                 break;
  1827.  
  1828.             case ';':                            /* comment found?         */
  1829.                 if (GetNextLine())               /* then skip rest of line */
  1830.                     return(0);
  1831.                 break;
  1832.  
  1833.             default:
  1834.                                                  /* was there a character? */
  1835.                 if (*actptr > ' ' && *actptr <= '~')
  1836.                     return(0);
  1837.                 else
  1838.                     actptr++;
  1839.         }
  1840.  
  1841.         if (actptr > buffend)                    /* end of file? */
  1842.             return(1);
  1843.     }
  1844. }
  1845.  
  1846.  
  1847.  
  1848.  
  1849.  
  1850. /******************************************************************************
  1851. ** GetNextLine()
  1852. *******************************************************************************
  1853. ** input:   none
  1854. **
  1855. ** output:  0: line found, actptr points to this line
  1856. **          1: end of file reached
  1857. **
  1858. ** remarks: gets pointer to next line
  1859. ******************************************************************************/
  1860.  
  1861. int GetNextLine(void)
  1862. {
  1863.  
  1864.     for(;;)
  1865.     {
  1866.         if (*actptr == 0x0A)
  1867.         {
  1868.             actptr++;
  1869.             linenum++;
  1870.             return(0);
  1871.         }
  1872.  
  1873.         if (actptr > buffend)                       /* end of file? */
  1874.             return(1);
  1875.  
  1876.         actptr++;
  1877.     }
  1878. }
  1879.  
  1880.  
  1881.  
  1882.  
  1883.  
  1884. /******************************************************************************
  1885. ** AsmError()
  1886. *******************************************************************************
  1887. ** input:   errornum    number of error to be printed
  1888. **          pinnum      = 0: print "Error in line linnum:" ...
  1889. **                      > 0: print "Pin pinnum:" ...
  1890. **
  1891. ** output:  none
  1892. **
  1893. ** remarks: print error messages of the GAL-assembler and free
  1894. **          the memory allocated by the file buffer
  1895. ******************************************************************************/
  1896.  
  1897. void AsmError(int errornum, int pinnum)
  1898. {
  1899.     static char pin[] = "Pin xx:";      /* this string is not localized  */
  1900.                                         /* since "pin" is a well known   */
  1901.                                         /* word for electronic freaks (or */
  1902.                                         /* isn't it?) */
  1903.     FreeMem(fbuff,fsize);
  1904.  
  1905.     TxtRequest(AppStrings[MSG_ERR_ASM].as_Str,
  1906.                AppStrings[MSG_CANCEL_GAD].as_Str, NULL);
  1907.  
  1908.     if (!pinnum)
  1909.         PrintErrorLine(linenum);
  1910.     else
  1911.     {
  1912.         sprintf(&pin[4], "%2d", pinnum);
  1913.         pin[6] = ':';
  1914.         PrintText(pin, 1);
  1915.     }
  1916.  
  1917.     switch (errornum)
  1918.     {
  1919.         case  1:
  1920.             PrintText(AppStrings[MSG_ERR_ASM1].as_Str, 1);
  1921.             break;
  1922.  
  1923.         case  2:
  1924.             PrintText(AppStrings[MSG_ERR_ASM2].as_Str, 1);
  1925.             break;
  1926.  
  1927.         case  3:
  1928.             PrintText(AppStrings[MSG_ERR_ASM3].as_Str, 1);
  1929.             break;
  1930.  
  1931.         case  4:
  1932.             PrintText(AppStrings[MSG_ERR_ASM4].as_Str, 1);
  1933.             break;
  1934.  
  1935.         case  5:
  1936.             PrintText(AppStrings[MSG_ERR_ASM5].as_Str, 1);
  1937.             break;
  1938.  
  1939.         case  6:
  1940.             PrintText(AppStrings[MSG_ERR_ASM6].as_Str, 1);
  1941.             break;
  1942.  
  1943.         case  7:
  1944.             PrintText(AppStrings[MSG_ERR_ASM7].as_Str, 1);
  1945.             break;
  1946.  
  1947.         case  8:
  1948.             PrintText(AppStrings[MSG_ERR_ASM8].as_Str, 1);
  1949.             break;
  1950.  
  1951.         case  9:
  1952.             PrintText(AppStrings[MSG_ERR_ASM9].as_Str, 1);
  1953.             break;
  1954.  
  1955.         case 10:
  1956.             PrintText(AppStrings[MSG_ERR_ASM10].as_Str, 1);
  1957.             break;
  1958.  
  1959.         case 11:
  1960.             PrintText(AppStrings[MSG_ERR_ASM11].as_Str, 1);
  1961.             break;
  1962.  
  1963.         case 12:
  1964.             PrintText(AppStrings[MSG_ERR_ASM12].as_Str, 1);
  1965.             break;
  1966.  
  1967.         case 13:
  1968.             PrintText(AppStrings[MSG_ERR_ASM13].as_Str, 1);
  1969.             break;
  1970.  
  1971.         case 14:
  1972.             PrintText(AppStrings[MSG_ERR_ASM14].as_Str, 1);
  1973.             break;
  1974.  
  1975.         case 15:
  1976.             PrintText(AppStrings[MSG_ERR_ASM15].as_Str, 1);
  1977.             break;
  1978.  
  1979.         case 16:
  1980.             PrintText(AppStrings[MSG_ERR_ASM16].as_Str, 1);
  1981.             break;
  1982.  
  1983.         case 17:
  1984.             PrintText(AppStrings[MSG_ERR_ASM17].as_Str, 1);
  1985.             break;
  1986.      
  1987.         case 18:
  1988.             PrintText(AppStrings[MSG_ERR_ASM18].as_Str, 1);
  1989.             break;
  1990.  
  1991.         case 19:
  1992.             PrintText(AppStrings[MSG_ERR_ASM19].as_Str, 1);
  1993.             break;
  1994.  
  1995.         case 20:
  1996.             PrintText(AppStrings[MSG_ERR_ASM20].as_Str, 1);
  1997.             break;
  1998.  
  1999.         case 21:
  2000.             PrintText(AppStrings[MSG_ERR_ASM21].as_Str, 1);
  2001.             break;
  2002.  
  2003.         case 22:
  2004.             PrintText(AppStrings[MSG_ERR_ASM22].as_Str, 1);
  2005.             break;
  2006.  
  2007.         case 23:
  2008.             PrintText(AppStrings[MSG_ERR_ASM23].as_Str, 1);
  2009.             break;
  2010.  
  2011.         case 24:
  2012.             PrintText(AppStrings[MSG_ERR_ASM24].as_Str, 1);
  2013.             break;
  2014.  
  2015.         case 25:
  2016.             PrintText(AppStrings[MSG_ERR_ASM25].as_Str, 1);
  2017.             break;
  2018.  
  2019.         case 26:
  2020.             PrintText(AppStrings[MSG_ERR_ASM26].as_Str, 1);
  2021.             break;
  2022.  
  2023.         case 27:
  2024.             PrintText(AppStrings[MSG_ERR_ASM27].as_Str, 1);
  2025.             break;
  2026.  
  2027.         case 28:
  2028.             PrintText(AppStrings[MSG_ERR_ASM28].as_Str, 1);
  2029.             break;
  2030.  
  2031.         case 29:
  2032.             PrintText(AppStrings[MSG_ERR_ASM29].as_Str, 1);
  2033.             break;
  2034.  
  2035.         case 30:
  2036.             PrintText(AppStrings[MSG_ERR_ASM30].as_Str, 1);
  2037.             break;
  2038.  
  2039.         case 31:
  2040.             PrintText(AppStrings[MSG_ERR_ASM31].as_Str, 1);
  2041.             break;
  2042.  
  2043.         case 32:
  2044.             PrintText(AppStrings[MSG_ERR_ASM32].as_Str, 1);
  2045.             break;
  2046.  
  2047.         case 33:
  2048.             PrintText(AppStrings[MSG_ERR_ASM33].as_Str, 1);
  2049.             break;
  2050.  
  2051.         case 34:
  2052.             PrintText(AppStrings[MSG_ERR_ASM34].as_Str, 1);
  2053.             break;
  2054.  
  2055.         case 35:
  2056.             PrintText(AppStrings[MSG_ERR_ASM35].as_Str, 1);
  2057.             break;
  2058.  
  2059.         case 36:
  2060.             PrintText(AppStrings[MSG_ERR_ASM36].as_Str, 1);
  2061.             break;
  2062.  
  2063.         case 37:
  2064.             PrintText(AppStrings[MSG_ERR_ASM37].as_Str, 1);
  2065.             break;
  2066.  
  2067.         case 38:
  2068.             PrintText(AppStrings[MSG_ERR_ASM38].as_Str, 1);
  2069.             break;
  2070.  
  2071.         case 39:
  2072.             PrintText(AppStrings[MSG_ERR_ASM39].as_Str, 1);
  2073.             break;
  2074.  
  2075.         case 40:
  2076.             PrintText(AppStrings[MSG_ERR_ASM40].as_Str, 1);
  2077.             break;
  2078.  
  2079.         case 41:
  2080.             PrintText(AppStrings[MSG_ERR_ASM41].as_Str, 1);
  2081.             break;
  2082.  
  2083.         case 42:
  2084.             PrintText(AppStrings[MSG_ERR_ASM42].as_Str, 1);
  2085.             break;
  2086.  
  2087.         case 43:
  2088.             PrintText(AppStrings[MSG_ERR_ASM43].as_Str, 1);
  2089.             break;
  2090.  
  2091.         case 44:
  2092.             PrintText(AppStrings[MSG_ERR_ASM44].as_Str, 1);
  2093.             break;
  2094.  
  2095.         case 45:
  2096.             PrintText(AppStrings[MSG_ERR_ASM45].as_Str, 1);
  2097.             break;
  2098.  
  2099.         case 46:
  2100.             PrintText(AppStrings[MSG_ERR_ASM46].as_Str, 1);
  2101.             break;
  2102.  
  2103.         case 47:
  2104.             PrintText(AppStrings[MSG_ERR_ASM47].as_Str, 1);
  2105.             break;
  2106.  
  2107.         case 48:
  2108.             PrintText(AppStrings[MSG_ERR_ASM48].as_Str, 1);
  2109.             break;
  2110.     }
  2111.  
  2112.  
  2113.  
  2114.  
  2115.  
  2116. /******************************************************************************
  2117. ** IsOR()
  2118. *******************************************************************************
  2119. ** input:   none
  2120. **
  2121. ** output:  1: chr is a OR
  2122. **          0: chr is no OR
  2123. **
  2124. ** remarks: checks whether or not chr is a OR sign or not
  2125. ******************************************************************************/
  2126.  
  2127. int IsOR(char chr)
  2128. {
  2129.     if (chr == '+' || chr == '#')
  2130.         return(1);
  2131.     else
  2132.         return(0);
  2133. }
  2134.  
  2135.  
  2136.  
  2137.  
  2138.  
  2139. /******************************************************************************
  2140. ** IsAND()
  2141. *******************************************************************************
  2142. ** input:   none
  2143. **
  2144. ** output:  1: chr is a AND
  2145. **          0: chr is no AND
  2146. **
  2147. ** remarks: checks whether or not chr is a AND sign or not
  2148. ******************************************************************************/
  2149.  
  2150. int IsAND(char chr)
  2151. {
  2152.     if (chr == '*' || chr == '&')
  2153.         return(1);
  2154.     else
  2155.         return(0);
  2156. }
  2157.  
  2158.  
  2159.  
  2160.  
  2161.  
  2162. /******************************************************************************
  2163. ** IsNEG()
  2164. *******************************************************************************
  2165. ** input:   none
  2166. **
  2167. ** output:  1: chr is a negation sign
  2168. **          0: chr is no negation sign
  2169. **
  2170. ** remarks: checks whether or not chr is a negation sign or not
  2171. ******************************************************************************/
  2172.  
  2173. int IsNEG(char chr)
  2174. {
  2175.     if (chr == '/' || chr == '!')
  2176.         return(1);
  2177.     else
  2178.         return(0);
  2179. }
  2180.  
  2181.  
  2182.  
  2183.  
  2184.  
  2185.  
  2186. /********************************************************/
  2187. /* the following routines are for the creation of the   */
  2188. /* documentation files                                  */
  2189. /********************************************************/
  2190.  
  2191.  
  2192.  
  2193.  
  2194.  
  2195. /******************************************************************************
  2196. ** WriteChipFile()
  2197. *******************************************************************************
  2198. ** input:   none
  2199. **
  2200. ** output:  none
  2201. **
  2202. ** remarks: make chip file
  2203. ******************************************************************************/
  2204.  
  2205. void WriteChipFile(void)
  2206. {
  2207.     extern  char    path;
  2208.     FILE    *fp;
  2209.     int     n;
  2210.  
  2211.     if (MyFileReq(AppStrings[MSG_WRITE_CHIP].as_Str, ".chp",
  2212.                   !Config.AutoSave, SAVE))
  2213.     {
  2214.  
  2215.         PrintText(AppStrings[MSG_WRITING_CHIP].as_Str, 1);
  2216.  
  2217.         if (fp = fopen(&path, (char *)"w"))
  2218.         {
  2219.  
  2220.             fprintf(fp, "\n\n");
  2221.  
  2222.             WriteSpaces(fp, 31);
  2223.  
  2224.             if (gal_type == GAL16V8)
  2225.                 fprintf(fp, " GAL16V8\n\n");
  2226.  
  2227.             if (gal_type == GAL20V8)
  2228.                 fprintf(fp, " GAL20V8\n\n");
  2229.  
  2230.             if (gal_type == GAL22V10)
  2231.                 fprintf(fp, " GAL22V10\n\n");
  2232.  
  2233.             if (gal_type == GAL20RA10)
  2234.                 fprintf(fp, "GAL20RA10\n\n");
  2235.  
  2236.  
  2237.             WriteSpaces(fp, 26);
  2238.  
  2239.             fprintf(fp,"-------\\___/-------\n");
  2240.  
  2241.             for (n = 0; n < num_of_pins/2; n++)
  2242.             {
  2243.  
  2244.                 WriteSpaces(fp, 25 - (int)strlen((char *)(pinnames+n*10)));
  2245.  
  2246.                 fprintf(fp,"%s | %2d           %2d | %s\n", pinnames + n*10,
  2247.                         n+1, num_of_pins-n, pinnames+(num_of_pins-n-1)*10);
  2248.  
  2249.                 if (n < num_of_pins/2 - 1)
  2250.                 {
  2251.                     WriteSpaces(fp, 26);
  2252.  
  2253.                     fprintf(fp, "|                 |\n");
  2254.                 }
  2255.             }
  2256.  
  2257.             WriteSpaces(fp, 26);
  2258.  
  2259.             fprintf(fp, "-------------------\n");
  2260.  
  2261.             if (fclose(fp) == EOF)
  2262.             {
  2263.                 PrintText(AppStrings[MSG_ERROR].as_Str, 0);
  2264.                 ErrorReq(8);                   /* can't close file */
  2265.                 return;
  2266.             }
  2267.         }
  2268.         else
  2269.         {
  2270.             PrintText(AppStrings[MSG_ERROR].as_Str, 0);
  2271.             ErrorReq(13);
  2272.             return;
  2273.         }
  2274.  
  2275.         PrintText(AppStrings[MSG_LOWER_OK].as_Str, 0);
  2276.     }
  2277. }
  2278.  
  2279.  
  2280.  
  2281.  
  2282.  
  2283. /******************************************************************************
  2284. ** WritePinFile()
  2285. *******************************************************************************
  2286. ** input:   none
  2287. **
  2288. ** output:  none
  2289. **
  2290. ** remarks: make pin file
  2291. ******************************************************************************/
  2292.  
  2293. void WritePinFile(void)
  2294. {
  2295.     extern  char    path;
  2296.     FILE    *fp;
  2297.     int     k, n, flag;
  2298.  
  2299.  
  2300.     if (MyFileReq(AppStrings[MSG_WRITE_PIN].as_Str, ".pin",
  2301.                   !Config.AutoSave, SAVE))
  2302.     {
  2303.  
  2304.         PrintText(AppStrings[MSG_WRITING_PIN].as_Str, 1);
  2305.  
  2306.         if (fp = fopen(&path, (char *)"w"))
  2307.         {
  2308.             fprintf(fp, "\n\n");
  2309.  
  2310.             fprintf(fp, " Pin # | Name     | Pin Type\n");
  2311.  
  2312.             fprintf(fp, "-----------------------------\n");
  2313.  
  2314.             for (n = 1; n <= num_of_pins; n++)
  2315.             {
  2316.                 fprintf(fp,"  %2d   | ",n);
  2317.  
  2318.                 fprintf(fp,"%s",pinnames+(n-1)*10);
  2319.  
  2320.                 WriteSpaces(fp, 9-(int)strlen((char *)(pinnames+(n-1)*10)));
  2321.  
  2322.                 flag = 0;
  2323.  
  2324.                 if (n == num_of_pins/2)
  2325.                 {
  2326.                     fprintf(fp,"| GND\n");
  2327.                     flag = 1;
  2328.                 }
  2329.  
  2330.                 if (n == num_of_pins)
  2331.                 {
  2332.                     fprintf(fp,"| VCC\n\n");
  2333.                     flag = 1;
  2334.                 }
  2335.  
  2336.  
  2337.                 if (gal_type == GAL16V8 || gal_type == GAL20V8)
  2338.                 {
  2339.  
  2340.                     if (modus == MODE3 && n == 1)
  2341.                     {
  2342.                         fprintf(fp, "| Clock\n");
  2343.                         flag = 1;
  2344.                     }
  2345.  
  2346.                     if (modus == MODE3)
  2347.                     {
  2348.                         if (gal_type == GAL16V8 && n == 11)
  2349.                         {
  2350.                             fprintf(fp, "| /OE\n");
  2351.                             flag = 1;
  2352.                         }
  2353.  
  2354.                         if (gal_type == GAL20V8 && n == 13)
  2355.                         {
  2356.                             fprintf(fp, "| /OE\n");
  2357.                             flag = 1;
  2358.                         }
  2359.                     }
  2360.                 }
  2361.  
  2362.                 if (gal_type == GAL22V10 && n == 1)
  2363.                 {
  2364.                     fprintf(fp, "| Clock/Input\n");
  2365.                     flag = 1;
  2366.                 }
  2367.  
  2368.                                                         /* OLMC pin?*/
  2369.  
  2370.                 if ((gal_type == GAL16V8   && n >= 12 && n <= 19) ||
  2371.                     (gal_type == GAL20V8   && n >= 15 && n <= 22) ||
  2372.                     (gal_type == GAL20RA10 && n >= 14 && n <= 23) ||
  2373.                     (gal_type == GAL22V10  && n >= 14 && n <= 23))
  2374.                 {
  2375.  
  2376.  
  2377.                     if (gal_type == GAL16V8)
  2378.                         k = n - 12;
  2379.                     else
  2380.                         if (gal_type == GAL20V8)
  2381.                             k = n - 15;
  2382.                         else
  2383.                             k = n - 14;
  2384.  
  2385.                     if (OLMC[k].PinType != INPUT)
  2386.                         if (OLMC[k].PinType)
  2387.                             fprintf(fp,"| Output\n");
  2388.                         else
  2389.                             fprintf(fp,"| NC\n");
  2390.                     else
  2391.                         fprintf(fp,"| Input\n");
  2392.                 }
  2393.                 else
  2394.                 {
  2395.                     if (!flag)
  2396.                         fprintf(fp,"| Input\n");
  2397.                 }
  2398.             }
  2399.  
  2400.             if (fclose(fp) == EOF)
  2401.             {
  2402.                 PrintText(AppStrings[MSG_ERROR].as_Str, 0);
  2403.                 ErrorReq(8);                           /* can't close file */
  2404.                 return;
  2405.             }
  2406.         }
  2407.         else
  2408.         {
  2409.             PrintText(AppStrings[MSG_ERROR].as_Str, 0);
  2410.             ErrorReq(13);
  2411.             return;
  2412.         }
  2413.  
  2414.         PrintText(AppStrings[MSG_LOWER_OK].as_Str, 0);
  2415.     }
  2416. }
  2417.  
  2418.  
  2419.  
  2420.  
  2421.  
  2422. /******************************************************************************
  2423. ** WriteRow()
  2424. *******************************************************************************
  2425. ** input:   *fp     pointer to the file handle
  2426. **          row     number of row which should be written
  2427. **
  2428. **          global: row_of_col
  2429. **
  2430. ** output:  none
  2431. **
  2432. ** remarks: writes a row of an OLMC to the file characterized by the file
  2433. **          handle fp
  2434. ******************************************************************************/
  2435.  
  2436. void WriteRow(FILE *fp, int row)
  2437. {
  2438.     int col;
  2439.  
  2440.  
  2441.     fprintf(fp, "\n%3d ", row);                 /* print row number */
  2442.  
  2443.     for (col = 0; col < num_of_col; col++)
  2444.     {                                           /* print fuses of */
  2445.         if (!((col) % 4))                       /* a row          */
  2446.             fprintf(fp, " ");
  2447.  
  2448.         if (Jedec.GALLogic[row*num_of_col + col])
  2449.             fprintf(fp, "-");
  2450.         else
  2451.             fprintf(fp, "x");
  2452.     }
  2453. }
  2454.  
  2455.  
  2456.  
  2457.  
  2458.  
  2459. /******************************************************************************
  2460. ** WriteChipFile()
  2461. *******************************************************************************
  2462. ** input:   none
  2463. **
  2464. ** output:  none
  2465. **
  2466. ** remarks: make fuse file
  2467. ******************************************************************************/
  2468.  
  2469. void WriteFuseFile(void)
  2470. {
  2471.     extern  char    path;
  2472.     FILE    *fp;
  2473.     int     row, pin, n, numofOLMCs, numofrows, olmc;
  2474.  
  2475.  
  2476.     if (MyFileReq(AppStrings[MSG_WRITE_FUSE].as_Str, ".fus",
  2477.                   !Config.AutoSave, SAVE))
  2478.     {
  2479.         PrintText(AppStrings[MSG_WRITING_FUSE].as_Str, 1);
  2480.  
  2481.         if (fp = fopen(&path, (char *)"w"))
  2482.         {
  2483.             if (gal_type == GAL16V8)
  2484.             {
  2485.                 pin = 19;
  2486.                 numofOLMCs = 8;
  2487.             }
  2488.             else
  2489.                 if (gal_type == GAL20V8)
  2490.                 {
  2491.                     pin = 22;
  2492.                     numofOLMCs = 8;
  2493.                 }
  2494.                 else
  2495.                 {                                  /* 22V10, 20RA10 */
  2496.                     pin = 23;
  2497.                     numofOLMCs = 10;
  2498.                 }
  2499.  
  2500.  
  2501.  
  2502.             row = 0;
  2503.  
  2504.             for (olmc = 0; olmc < numofOLMCs; olmc++)
  2505.             {
  2506.  
  2507.                 if (gal_type == GAL22V10 && olmc == 0)
  2508.                 {                               /* AR when 22V10 */
  2509.                     fprintf(fp, "\n\nAR");
  2510.                     WriteRow(fp, row);
  2511.                     row++;
  2512.                 }
  2513.  
  2514.                 if (gal_type == GAL22V10)             /* get number of rows */
  2515.                     numofrows = OLMCSize22V10[olmc];  /* of an OLMC         */
  2516.                 else
  2517.                     numofrows = 8;
  2518.  
  2519.  
  2520.  
  2521.                 fprintf(fp, "\n\nPin %2d = ", pin);             /* print pin */
  2522.  
  2523.                 fprintf(fp, "%s", pinnames + (pin - 1)*10);
  2524.  
  2525.                 WriteSpaces(fp, 13-(int)strlen((char *)(pinnames+(pin-1)*10)));
  2526.  
  2527.  
  2528.                 if (gal_type == GAL16V8)
  2529.                     fprintf(fp, "XOR = %1d   AC1 = %1d", Jedec.GALXOR[19-pin],
  2530.                             Jedec.GALAC1[19 - pin]);
  2531.                 else
  2532.                     if (gal_type == GAL20V8)
  2533.                         fprintf(fp, "XOR = %1d   AC1 = %1d",
  2534.                                 Jedec.GALXOR[22 - pin], Jedec.GALAC1[22 - pin]);
  2535.                     else
  2536.                         if (gal_type == GAL22V10)
  2537.                             fprintf(fp, "S0 = %1d   S1 = %1d",
  2538.                                     Jedec.GALXOR[23 - pin],
  2539.                                     Jedec.GALAC1[23 - pin]);
  2540.                         else
  2541.                             if (gal_type == GAL20RA10)
  2542.                                 fprintf(fp, "S0 = %1d",
  2543.                                         Jedec.GALXOR[23 - pin]);
  2544.  
  2545.  
  2546.  
  2547.                 for (n = 0; n < numofrows; n++)
  2548.                 {                           /* print all fuses of an OLMC */
  2549.                     WriteRow(fp, row);
  2550.                     row++;
  2551.                 }
  2552.  
  2553.  
  2554.                 if (gal_type == GAL22V10 && olmc == 9)
  2555.                 {                                        /* SP when 22V10 */
  2556.                     fprintf(fp, "\n\nSP");
  2557.                     WriteRow(fp, row);
  2558.                 }
  2559.  
  2560.                 pin--;
  2561.             }
  2562.  
  2563.  
  2564.             fprintf(fp, "\n\n");
  2565.  
  2566.             if (fclose(fp) == EOF)
  2567.             {
  2568.                 PrintText(AppStrings[MSG_ERROR].as_Str, 0);
  2569.                 ErrorReq(8);                            /* can't close file */
  2570.                 return;
  2571.             }
  2572.         }
  2573.         else
  2574.         {
  2575.             PrintText(AppStrings[MSG_ERROR].as_Str, 0);
  2576.             ErrorReq(13);
  2577.             return;
  2578.         }
  2579.  
  2580.         PrintText(AppStrings[MSG_LOWER_OK].as_Str, 0);
  2581.     }
  2582. }
  2583.  
  2584.  
  2585.  
  2586.  
  2587.  
  2588. /******************************************************************************
  2589. ** WriteSpaces()
  2590. *******************************************************************************
  2591. ** input:   *fp         pointer to the file handle of the file
  2592. **          numof       number of spaces to be written to the file
  2593. **
  2594. ** output:  none
  2595. **
  2596. ** remarks: write "numof" spaces to the file characterized by *fp
  2597. ******************************************************************************/
  2598.  
  2599. void WriteSpaces(FILE *fp, int numof)
  2600. {
  2601.     int n;
  2602.  
  2603.     for (n = 0; n < numof; n++)
  2604.         fprintf(fp, " ");
  2605.  
  2606. }
  2607.  
  2608.  
  2609.  
  2610.  
  2611.  
  2612. /* EOF */
  2613.